package com.lxw.manage_cms.controller;

import com.lxw.api.cms.CmsPageControllerApi;
import com.lxw.framework.domain.cms.CmsPage;
import com.lxw.framework.domain.cms.request.QueryPageRequest;
import com.lxw.framework.domain.cms.response.CmsPageResult;
import com.lxw.framework.model.response.CommonCode;
import com.lxw.framework.model.response.QueryResponseResult;
import com.lxw.framework.model.response.QueryResult;
import com.lxw.manage_cms.service.CmsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cmsPage")
public class CmsPageController implements CmsPageControllerApi {
    @Autowired
    CmsPageService cmsPageService;

    //分页查询请求接口
    @Override
    @GetMapping("/findList")
    public QueryResponseResult findList(Integer page, Integer pageSize, QueryPageRequest queryPageRequest) {
        //调用service方法，处理业务
        Page<CmsPage> pages = cmsPageService.findList(page, pageSize, queryPageRequest);
        QueryResult<CmsPage> cmsPageQueryResult = new QueryResult<CmsPage>();
        cmsPageQueryResult.setList(pages.getContent());
        cmsPageQueryResult.setTotal(pages.getTotalElements());
        return new QueryResponseResult(CommonCode.SUCCESS, cmsPageQueryResult);
    }

    @Override
    @PostMapping("/add")
    public CmsPageResult add(@RequestBody CmsPage cmsPage) {
        cmsPage = cmsPageService.add(cmsPage);
        return new CmsPageResult(CommonCode.SUCCESS, cmsPage);
    }

    @Override
    @GetMapping("/fiandById")
    public CmsPageResult fiandById(String id) {
        return cmsPageService.findById(id);
    }

    @Override
    @RequestMapping(value = "/edit/{id}", method = {RequestMethod.POST, RequestMethod.PUT})
    public CmsPageResult edit(@PathVariable String id, @RequestBody CmsPage cmsPage) {
        return cmsPageService.edit(id, cmsPage);
    }

    @Override
    @GetMapping("/deleteById")
    public CmsPageResult deleteById(@RequestParam("id") String id) {
        return cmsPageService.deleteById(id);
    }

    @Override
    @GetMapping("/pagePost/{id}")
    public CmsPageResult pagePost(@PathVariable String id) {
        return cmsPageService.pagePost(id);

    }


}
